package com.ybxx.hr.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;
import com.ybxx.hr.model.School;
import com.ybxx.hr.service.SchoolService;

public class SchoolAction extends BaseAction {
	@Resource
	private SchoolService schoolService;
	private School school;
	private List<School> schools;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			schoolService.remove(school.getSid());
		}catch(Exception ex){
			msg="文化程度删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(school!=null && StringUtils.isNotEmpty(school.getSid())){
			school=schoolService.get(school.getSid());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		schools=schoolService.queryPage(school,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(school.getSid())){
			school.setSid(UUIDGenerator.getUUID());
		}
		try{
			schoolService.save(school);
		}catch(Exception ex){
			msg="学历信息保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(school!=null && StringUtils.isNotEmpty(school.getSid())){
			school=schoolService.get(school.getSid());
		}
		return "load";
	}
	public School getSchool() {
		return school;
	}
	public void setSchool(School school) {
		this.school = school;
	}
	public List<School> getSchools() {
		return schools;
	}
	public void setSchools(List<School> schools) {
		this.schools = schools;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
}
